package com.example.visitor.visit;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ycd0075
 * @date 2024-01-25 17:28
 */
public class ManagerElement {

    private List<Element> elements = new ArrayList<>();

    public void add(Element element) {
        {
            elements.add(element);
        }

    }

    public void remove(Element element) {
        elements.remove(element);
    }

    /**
     * 大家来排队接受访问
     *
     * @param elements
     * @param visitor
     */
    public void execute(List<Element> elements, Visitor visitor) {
        for (Element element : elements) {
            System.out.println("访问者" + visitor.getClass().getName() + "访问了元素" + element.getClass().getName());
            element.accept(visitor);
        }
    }

    public List<Element> getElements() {
        return elements;
    }

    public void setElements(List<Element> elements) {
        this.elements = elements;
    }
}